package com.xy.modulemain.viewmodel

import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.ToastUtils
import com.xy.modulemain.bean.Item
import com.xy.modulemain.bean.PagingResult
import com.xy.modulemain.lisener.IBaseModelListener
import com.xy.modulemain.model.ItemModel
import com.xy.modulemain.model.MainModel

/**
 * @ClassName MainViewModel
 * @Author xy
 * @Date 2021/8/25 17:09
 * @Description 描述
 */
class MainViewModel :IBaseModelListener<MutableList<String>> {

    var itemModel:MainModel = MainModel()
    var titleList = MutableLiveData<MutableList<String>>().apply {
        value = mutableListOf()
    }

    constructor(){
        itemModel.getCacheDataAndLoad() //请求数据或缓存
        /**
         * 这里需要注册监听
         */

    }


    override fun onLoadFinish(t: MutableList<String>, vararg pagingResult: PagingResult) {
        titleList.value?.clear()
        titleList.value?.addAll(t)
        titleList.postValue(titleList.value)
    }

    override fun onLoadFailure(prompt: String) {
        ToastUtils.showShort(prompt)
    }
}